﻿using API_Service.BizLogic.BasicData;
using Nancy;

namespace API_Service.Module
{
    public class MasterDataSyncModule: BaseAPIModule
    {
        private MatDataMasterService _matMaster = new MatDataMasterService();
        private SKUService _skuSrvc = new SKUService();
        private MOBaseService _moSrvc = new MOBaseService();
        private BomDataService _bomSrvc = new BomDataService();
        private CustomService _customSrvc = new CustomService();

        public MasterDataSyncModule() : base("/mdsync")
        {
            Get["/"] = _ => Response.AsJson("ERP资料同步");
            #region 同步物料信息
            Post["/erpdata/matsync"] = _ =>
            {
                var result = new ExecutionResult<dynamic>();

                result = _matMaster.SyncMatMasterDataFromERP();

                return Response.AsJson(result);
            };

            //同步物料信息
            Post["/erpdata/skusync"] = _ =>
            {
                var result = new ExecutionResult<dynamic>();

                result = _skuSrvc.SyncSKUMasterDataFromERP();

                return Response.AsJson(result);
            };
            #endregion
            //同步工单信息
            Post["/erpdata/mosync"] = _ =>
            {
                var result = new ExecutionResult<dynamic>();

                result = _moSrvc.SyncMOMasterDataFromERP();

                return Response.AsJson(result);
            };
           
            //同步BOM信息
            Post["/erpdata/bommastersync"] = _ =>
            {
                var result = new ExecutionResult<dynamic>();

                result = _bomSrvc.SyncBomMasterDataFromERP();

                return Response.AsJson(result);
            };


            //同步BOM替代料信息
            Post["/erpdata/bomaltersync"] = _ =>
            {
                var result = new ExecutionResult<dynamic>();

                result = _bomSrvc.SyncBomAlterDataFromERP();

                return Response.AsJson(result);
            };

            //同步客户信息资料
            Post["/erpdata/customsync"] = _ =>
            {
                var result = new ExecutionResult<dynamic>();

                result = _customSrvc.SyncCustomDataFromERP();

                return Response.AsJson(result);
            };
        }
    }
}